ALMaSS  1.0
The Animal, Landscape and Man Simulation System
GeneticMaterial Class Reference

Class for the genetic material optionally carried by animals in ALMaSS. More...

#include <GeneticMaterial.h>

Public Member Functions

 GeneticMaterial ()
 
void ReadFrequencies ()
 
void SetAllele (int pos, uint32 value, int Chromosome)
 
uint32 GetAllele (int pos, int Chromosome)
 
void PrintChromosome (char *C, int Chromosome)
 
int HomozygosityCount ()
 
int HeterozygosityCount ()
 
void Recombine (GeneticMaterial *Gen21, GeneticMaterial *Gene2)
 
void Initiation (AlleleFreq *Al)
 
float ScoreReproduction ()
 
float ScoreHQThreshold ()
 
void SetGeneticFlag ()
 
void SetDirectFlag ()
 
void UnsetGeneticFlag ()
 
void UnsetDirectFlag ()
 
uint32 GetGeneticFlag ()
 
uint32 GetDirectFlag ()
 
void Mutation_1 ()
 
void Mutation_1ab ()
 
void Mutation_2 ()
 
void Mutation_3 ()
 
void Mutation_4 ()
 

Protected Attributes

uint32 Chromosome [6]
 

Detailed Description

Class for the genetic material optionally carried by animals in ALMaSS.

Constructor & Destructor Documentation

◆ GeneticMaterial()

GeneticMaterial::GeneticMaterial ( )
355  {
356  // ensure zeros in all loci
357  for ( int i = 0; i < 6; i++ ) Chromosome[ i ] = 0;
358 }
uint32 Chromosome[6]
Definition: GeneticMaterial.h:97

References Chromosome.

Member Function Documentation

◆ GetAllele()

uint32 GeneticMaterial::GetAllele ( int  pos,
int  Chromosome 
)
233  {
234  uint32 value;
235  // Get the right chromosome
236  // if Chromo==0 then 0-2, else 3-5
237  Chromo *= 3; // 0 or 3
238  if ( locus < 16 ) {
239  // Shift it so the locus is in the last two bits
240  // Does it twice because 32 bis coding for 16 loci
241  value = Chromosome[ Chromo ] >> locus;
242  value = ( value >> locus ) & 0x03;
243  } else {
244  Chromo++; // 1 or 4
245  locus -= 16; // Now 0 to 16
246  if ( locus >= 8 ) {
247  Chromo++; // 2 or 5
248  locus -= 8;
249  }
250  value = Chromosome[ Chromo ] >> ( locus * 4 );
251  value = value & 0x0f;
252  }
253  return value;
254 }
unsigned int uint32
Definition: ALMaSS_Setup.h:34

References Chromosome.

Referenced by GetDirectFlag(), GetGeneticFlag(), HeterozygosityCount(), HomozygosityCount(), Mutation_2(), Mutation_3(), Mutation_4(), PrintChromosome(), Recombine(), Vole_Base::SupplyAllele(), and Vole_Base::SupplyMyAllele().

◆ GetDirectFlag()

uint32 GeneticMaterial::GetDirectFlag ( )
191  {
192  return GetAllele(0,1);
193 }
uint32 GetAllele(int pos, int Chromosome)
Definition: GeneticMaterial.cpp:233

References GetAllele().

Referenced by Vole_Base::GetDirectFlag(), and Vole_JuvenileMale::st_BecomeSubAdult().

◆ GetGeneticFlag()

uint32 GeneticMaterial::GetGeneticFlag ( )
187  {
188  return GetAllele(0,0);
189 }

References GetAllele().

Referenced by Vole_Base::GetGeneticFlag(), and Vole_JuvenileMale::st_BecomeSubAdult().

◆ HeterozygosityCount()

int GeneticMaterial::HeterozygosityCount ( )
328  {
329  int heterozyg = 0;
330  for ( int i = 0; i < 32; i++ ) {
331  if ( GetAllele( i, 0 ) != GetAllele( i, 1 ) ) heterozyg++;
332  }
333  return heterozyg;
334 }

References GetAllele().

Referenced by Vole_Base::SupplyHeteroZyg().

◆ HomozygosityCount()

int GeneticMaterial::HomozygosityCount ( )
317  {
318  // OK OK there is an easy way to do this by calling HeterozygosityCount and
319  // subtracting this from 32, but just is case that little bit of saved time is useful:
320  int homozyg=0;
321  for ( int i = 0; i < 32; i++ ) {
322  if ( GetAllele( i, 0 ) == GetAllele( i, 1 ) ) homozyg++;
323  }
324  return homozyg;
325 }

References GetAllele().

Referenced by Vole_Base::SupplyHomoZyg().

◆ Initiation()

void GeneticMaterial::Initiation ( AlleleFreq Al)

The method called to intialise genes on initiation of the simulation.
Gene frequencies are based on an external text file input read in on construction.

366  {
367  uint32 value;
368  for ( int l = 0; l < 32; l++ ) {
369  //if ( l < 16 ) c = 0; else if ( l < 24 ) c = 1; else c = 2;
370 
371  int chance = random( 1000 );
372  uint32 index = 0;
373  while ( chance > Al->SupplyAN( l, index ) ) {
374  index++;
375  }
376  value = index;
377  // set the value
378  SetAllele( l, value, 0 );
379  chance = random( 1000 );
380  index = 0;
381  while ( chance > Al->SupplyAN( l, index ) ) {
382  index++;
383  }
384  value = index;
385  // set the value
386  SetAllele( l, value, 1 );
387  }
388 }
int random(int a_range)
Definition: ALMaSS_CmdLine.cpp:142
int SupplyAN(int loc, int al)
Definition: GeneticMaterial.h:71
void SetAllele(int pos, uint32 value, int Chromosome)
Definition: GeneticMaterial.cpp:196

References random(), SetAllele(), and AlleleFreq::SupplyAN().

Referenced by Vole_Population_Manager::Init().

◆ Mutation_1()

void GeneticMaterial::Mutation_1 ( )

random allele choice

445 {
446  for ( int i = 0; i < 16; i++ ) {
447  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
448  {
449  SetAllele( i, random( 4 ), random( 2 ) );
450  }
451  }
452  for ( int i = 16; i < 32; i++ ) {
453  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
454  {
455  SetAllele( i, random( 16 ), random( 2 ) );
456  }
457  }
458 }
double MutationChance
Definition: GeneticMaterial.cpp:52
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni

References g_rand_uni, MutationChance, random(), and SetAllele().

◆ Mutation_1ab()

void GeneticMaterial::Mutation_1ab ( )

random allele choice a & b only

466 {
467  // Only used when all loci have only two alleles!
468  for ( int i = 0; i < 32; i++ ) {
469  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
470  {
471  SetAllele( i, random( 2 ), random( 2 ) );
472  }
473  }
474 }

References g_rand_uni, MutationChance, random(), and SetAllele().

◆ Mutation_2()

void GeneticMaterial::Mutation_2 ( )

Move one allele +/-

482 {
483  for ( int i = 0; i < 16; i++ ) {
484  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
485  {
486  int strand = random( 2 );
487  int allele = GetAllele( i, strand );
488  if ( random( 2 ) == 1 ) allele++; else allele--;
489  if ( allele == -1 ) allele = 3; else if ( allele == 4 ) allele = 0;
490  SetAllele( i, allele, strand );
491  }
492  }
493  for ( int i = 16; i < 32; i++ ) {
494  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
495  {
496  int strand = random( 2 );
497  int allele = GetAllele( i, strand );
498  if ( random( 2 ) == 1 ) allele++; else allele--;
499  if ( allele == -1 ) allele = 15; else if ( allele == 16 ) allele = 0;
500  SetAllele( i, allele, strand );
501  }
502  }
503 }

References g_rand_uni, GetAllele(), MutationChance, random(), and SetAllele().

◆ Mutation_3()

void GeneticMaterial::Mutation_3 ( )

switch a<->b & c<->d

511 {
512  // NB Only works for the first 16 loci
513  for ( int i = 0; i < 16; i++ ) {
514  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
515  {
516  int strand = random( 2 );
517  int allele = GetAllele( i, strand );
518  switch ( allele ) {
519  case 0:
520  allele = 1;
521  break;
522  case 1:
523  allele = 0;
524  break;
525  case 2:
526  allele = 3;
527  break;
528  case 3:
529  allele = 2;
530  break;
531  }
532  SetAllele( i, allele, strand );
533  }
534  }
535 }

References g_rand_uni, GetAllele(), MutationChance, random(), and SetAllele().

◆ Mutation_4()

void GeneticMaterial::Mutation_4 ( )

Specially mutation of only the first locus with two options 0/1

539 {
541  if (g_rand_uni() < MutationChance) // one chance in Mutation Chance
542  {
543  int strand = random(2);
544  int allele = GetAllele(0, strand);
545  allele = (allele + 1) && 1; // only 1 or 0 is allowed
546  }
547 }

References g_rand_uni, GetAllele(), MutationChance, and random().

Referenced by Vole_Female::st_Lactating().

◆ PrintChromosome()

void GeneticMaterial::PrintChromosome ( char *  C,
int  Chromosome 
)
258  {
259  for ( int i = 0; i < 16; i++ ) {
260  uint32 allele = GetAllele( i, Chromo );
261  switch ( allele ) {
262  case 0:
263  C[ i ] = 'a';
264  break;
265  case 1:
266  C[ i ] = 'b';
267  break;
268  case 2:
269  C[ i ] = 'c';
270  break;
271  case 3:
272  C[ i ] = 'd';
273  break;
274  case 4:
275  C[ i ] = 'e';
276  break;
277  case 5:
278  C[ i ] = 'f';
279  break;
280  case 6:
281  C[ i ] = 'g';
282  break;
283  case 7:
284  C[ i ] = 'h';
285  break;
286  case 8:
287  C[ i ] = 'i';
288  break;
289  case 9:
290  C[ i ] = 'j';
291  break;
292  case 10:
293  C[ i ] = 'k';
294  break;
295  case 11:
296  C[ i ] = 'l';
297  break;
298  case 12:
299  C[ i ] = 'm';
300  break;
301  case 13:
302  C[ i ] = 'n';
303  break;
304  case 14:
305  C[ i ] = 'o';
306  break;
307  case 15:
308  C[ i ] = 'p';
309  break;
310  }
311  }
312  C[ 16 ] = 0;
313 }

References GetAllele().

◆ ReadFrequencies()

void GeneticMaterial::ReadFrequencies ( )

◆ Recombine()

void GeneticMaterial::Recombine ( GeneticMaterial Gen21,
GeneticMaterial Gene2 
)
338  {
339  for ( int i = 0; i < 32; i++ ) {
340  // For each locus
341  // Choose which chromosome for each parent
342  int g0 = random( 2 );
343  int g1 = random( 2 );
344  // get the two alleles
345  uint32 a0 = Gene1->GetAllele( i, g0 );
346  uint32 a1 = Gene2->GetAllele( i, g1 );
347  // put a0 into chromo0 & a1 to chromo1 & vice versa
348  SetAllele( i, a0, 0 );
349  SetAllele( i, a1, 1 );
350  }
351 }

References GetAllele(), random(), and SetAllele().

Referenced by Vole_Base::CopyMyself(), and Vole_Female::st_Lactating().

◆ ScoreHQThreshold()

float GeneticMaterial::ScoreHQThreshold ( )

This function can be used to alter fitness based on associated genetic codes. These are only used in population genetic research, e.g. to create hybrid zones.

414  {
415  return 1.0;
416  // OLD CODE OUTDATED
417  /* Ditte's Simulation Version uint32 allele0a = GetAllele(0,0); // loci 0 uint32 allele1a = GetAllele(1,0); // loci 1
418  uint32 allele0b = GetAllele(0,1); // loci 0 uint32 allele1b = GetAllele(1,1); // loci 1
419  // Initial rules are that if 0a and 1a are 0 & 2 or 2 & 0 then OK (a,c)(c,a)
420  // likewise they may be 1 & 3 or 3 & 1 (b,d) (d,b) // any other combination is bad // Same for loci 1 bool IsOK0=false;
421  switch(allele0a) { case 0: if (allele1a==2) IsOK0=true; break; case 1: if (allele1a==3) IsOK0=true; break; case 2:
422  if (allele1a==0) IsOK0=true; break; case 3: if (allele1a==1) IsOK0=true; break; default: assert(NULL); break; }
423  bool IsOK1=false; switch(allele0b) { case 0: if (allele1b==2) IsOK1=true; break; case 1: if (allele1b==3) IsOK1=true; break;
424  case 2: if (allele1b==0) IsOK1=true; break; case 3: if (allele1b==1) IsOK1=true; break; default: assert(NULL); break; }
425  // determine the effect of the genetics // In the simple case it is good or bad
426  if (IsOK0 && IsOK1) return 1.0; else return 0.9;
427 
428  // Lar Bach's version uint32 allele2a = GetAllele(2,0); // loci 0 uint32 allele2b = GetAllele(2,1); // loci 0
429  float result= -0.5; switch (allele2a) { case 0: case 2: case 3: break; default: result+=0.5; } switch (allele2b) { case 0:
430  case 2: case 3: break; default: result+=0.5; break; } return result;
431  // returns -0.5 if homozygous aa, 0.5 if homozygous bb & het=0
432 
433  */
434 }

◆ ScoreReproduction()

float GeneticMaterial::ScoreReproduction ( )

This function can be used to alter reproductive effects based on genetic codes. These are only used in population genetic research.

394  {
395  return 1.0;
396  /* OLD CODE OUTDATED uint32 allele0a = GetAllele(0,0); // loci 0 uint32 allele1a = GetAllele(1,0); // loci 1
397  uint32 allele0b = GetAllele(0,1); // loci 0 uint32 allele1b = GetAllele(1,1); // loci 1
398  // Initial rules are that locus 0 and 1 are ac or bd then OK // likewise they may be ca or db
399  // any other combination is bad // Same for loci 1 bool IsOK0=false; switch(allele0a) { case 0: //a
400  if (allele1a==2) IsOK0=true; break; case 1: //b if (allele1a==3) IsOK0=true; break; case 2: //c
401  if (allele1a==0) IsOK0=true; break; case 3: //d if (allele1a==1) IsOK0=true; break; default:
402  FILE* errfile=fopen("GeneticErrorFile.Txt","w"); fprintf(errfile,"Unknown Allele Number\n"); fclose(errfile); exit(10);
403  break; } bool IsOK1=false; switch(allele0b) { case 0: if (allele1b==2) IsOK1=true; break; case 1:
404  if (allele1b==3) IsOK1=true; break; case 2: if (allele1b==0) IsOK1=true; break; case 3: if (allele1b==1) IsOK1=true; break;
405  default: FILE* errfile=fopen("GeneticErrorFile.Txt","w"); fprintf(errfile,"Unknown Allele Number\n"); fclose(errfile);
406  exit(11); break; } // determine the effect of the genetics // In the simple case it is good or bad
407  if (IsOK0 && IsOK1) return 1.0; else return 0.05; */
408 }

◆ SetAllele()

void GeneticMaterial::SetAllele ( int  pos,
uint32  value,
int  Chromosome 
)
196  {
197  Chromo*=3; // now 0 or 3
198  uint32 mask;
199  if (locus<16) {
200  // Get the right chromosome
201  // Create the mask
202  // Does it twice because 32 bits coding for 16 loci
203  mask = 0x03 << locus;
204  mask = mask << locus;
205  // just to make make sure it is 0-3
206  value = value & 0x03;
207  // create the value mask
208  value = value << locus;
209  value = value << locus;
210  // clear the locus
211  Chromosome[ Chromo ] &= ~mask;
212  // write the value
213  Chromosome[ Chromo ] |= value;
214  } else {
215  Chromo++; // now 1 or 4
216  locus-=16;
217  if (locus>=8) {
218  Chromo++;
219  locus-=8;
220  }
221  mask = 0x0F << (locus*4);
222  value = value & 0x0f; // make sure there was no extra stuff added!
223  // create the value mask
224  value = value << (locus*4);
225  Chromosome[ Chromo ] &= ~mask;
226  // write the value
227  Chromosome[ Chromo ] |= value;
228  }
229 }

References Chromosome.

Referenced by Vole_Population_Manager::Init(), Initiation(), Mutation_1(), Mutation_1ab(), Mutation_2(), Mutation_3(), Recombine(), SetDirectFlag(), SetGeneticFlag(), UnsetDirectFlag(), and UnsetGeneticFlag().

◆ SetDirectFlag()

void GeneticMaterial::SetDirectFlag ( )
173  {
174  SetAllele(0,1,1);
175 }

References SetAllele().

Referenced by Vole_Base::SetDirectFlag().

◆ SetGeneticFlag()

void GeneticMaterial::SetGeneticFlag ( )
169  {
170  SetAllele(0,1,0);
171 }

References SetAllele().

Referenced by Vole_Base::SetGeneticFlag().

◆ UnsetDirectFlag()

void GeneticMaterial::UnsetDirectFlag ( )
182  {
183  SetAllele(0,0,1);
184 }

References SetAllele().

Referenced by Vole_Base::UnsetDirectFlag().

◆ UnsetGeneticFlag()

void GeneticMaterial::UnsetGeneticFlag ( )
178  {
179  SetAllele(0,0,0);
180 }

References SetAllele().

Referenced by Vole_Base::UnsetGeneticFlag().

Member Data Documentation

◆ Chromosome

uint32 GeneticMaterial::Chromosome[6]
protected

The documentation for this class was generated from the following files: